package com.ruicar.afs.cloud.demo.demo.datascope.controller;

import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.common.data.mybatis.plugin.datascope.DataScope;
import com.ruicar.afs.cloud.demo.demo.datascope.mapper.DemoMapper;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
@RequestMapping("/queryRole")
@AllArgsConstructor
public class DataScopeController {
    private final DemoMapper demoMapper;
    @GetMapping("/role/{type}")
    public IResponse queryRole(@PathVariable String type){
        if("1".equalsIgnoreCase(type)){
            DataScope dataScope = new DataScope();
            dataScope.setScopeName("role_code");
            dataScope.setScopeValues(Arrays.asList("ROLE_ADMIN"));
            return IResponse.success(demoMapper.queryRole(dataScope));
        }else{
            return IResponse.success(demoMapper.queryRole(null));
        }
    }
}
